<template>
	<div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="时间">
							<a-range-picker v-decorator="['data']"/>
						</a-form-item>
					</a-col>
					<a-col :span="16" style="margin-top: 2px;">
						<a-button type="primary" html-type="submit">搜索</a-button>
						<a-button @click="handleReset" class="btn2">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="table">
			<el-table :data="data" v-loading="loading" stripe :max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
				<el-table-column prop="Title" label="类型/标题" min-width="330" fixed="left">
					<template slot-scope="scope">
						<a-tag color="red">{{ scope.row.TypeName }}</a-tag>
						{{ scope.row.Title || scope.row.TypeItemName }}
					</template>
				</el-table-column>
				<el-table-column prop="ClassName" label="学生组织/班级" min-width="200" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.ClubName || scope.row.ClassName }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="ChargeUserNo" label="发起人" min-width="100" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.ChargeUserNo }}</div>
						<div>{{ scope.row.ChargeUserName }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="MemberNum" label="参加人数" min-width="90" align="right"></el-table-column>
				<el-table-column prop="StartTime" label="开始时间/结束时间" min-width="160" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.StartTime }}</div>
						<div>{{ scope.row.EndTime }}</div>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page="pagination.currentPage"
				:page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"
			></el-pagination>
		</div>
	</div>
</template>

<script>
import moment from 'moment'
import { UserClassStudentDoGetActivityPageList } from '@/api/follow';
const data = [];
export default {
	components: {
	},
	data() {
		return {
			data,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			loading: false,
			values: {},
			tableHeight: parseFloat(window.innerHeight - 160),
			requestUrl:this.global.requestUrl
		};
	},
	computed: {},
	created() {
		this.getList();
	},
	mounted() {},
	methods: {
		moment,
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				if (values.data&&values.data.length>0) {
					values.startTime = values.data[0].format('YYYY-MM-DD')
					values.endTime = values.data[1].format('YYYY-MM-DD')
				}
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}
			data.id = this.$route.query.ID
			data.pageIndex = this.pagination.currentPage;
			data.pageSize = this.pagination.pageSize;
			let res = await UserClassStudentDoGetActivityPageList(data);
			this.loading = false;
			this.data = res.data.data;
			const pagination = { ...this.pagination };
			pagination.total = res.data.pageInfo.TotalItemCount;
			this.pagination = pagination;
		},
	}
};
</script>

